#lang sicp

(define (square x)
  (* x x))

(define (fast-expt a n)
  (define (iter a n ans)
    (cond ((= n 0) ans)
          ((odd? n) (iter (square a) (quotient n 2) (* ans a)))
          (else (iter (square a) (quotient n 2) ans))))
          
  (iter a n 1))